#ifndef _STRINGFILTER_H_
#define _STRINGFILTER_H_

#pragma warning ( disable:4786 )
#pragma warning ( disable:4503 )

#include <windows.h>
#include <map>
#include <functional>
#include <utillib/util/SingleTon.h>
#include <UtilLib/string/StringTokenizer.h>

#define			MAX_FILTER_TOKEN_SIZE		256

namespace utillib
{
	namespace string
	{
		class StringFilter 
		{
		private:
			class Node
			{
			private:
				typedef std::map< BYTE, Node * > mapNodeList;
			public:
				Node()
				{
					termination = false;
				};
				virtual ~Node()
				{
					{
						for ( mapNodeList::iterator iter = m_childList.begin() ; iter != m_childList.end(); ++iter )
						{
							Node *node = ( *iter ).second;
							delete node;
						}
						m_childList.clear();
					}
				};

				void add( BYTE code, Node *node )
				{
					m_childList.insert( mapNodeList::value_type( code, node ) );
				};
				Node *find( BYTE code )
				{
					mapNodeList::iterator iter = m_childList.find( code );
					if ( iter != m_childList.end() ) return ( *iter ).second;
					return ( NULL );
				};

				size_t size()
				{
					return m_childList.size();
				}

				bool termination;
				mapNodeList m_childList;
			};

		protected:			

		public:
			StringFilter();
			virtual ~StringFilter();

		public:
			bool initialize( const char *filename );
			bool initializeStream( const char *stream );
		public:
			bool checkComposition( char *checkComposition , char filteredText, int checkSize = -1 );
			char *checkComposition( char *checkComposition  , int checkSize = -1 );
			void add( const char *checkToken );
		private:
			bool readFile( const char *filename , char *keyValue = NULL );
			bool readStream( const char *stream );
			bool checkString( char *checkToken, int *checkCount, Node *node = NULL );

			void release();

		private:
			Node *m_rootNode;
			char m_resultFindedText[ MAX_FILTER_TOKEN_SIZE ];

		public:
			static void encryptFile( const char *filename, const char *targetFileName , char *keyValue );
		};
	}
}

#endif